// pages/message/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //模拟数据
    msgInfo: [],
    msgAll: [],
    start: 0, //渲染开始位置
    skipNum: 10, //追加数据数量
  },

  readReport:function(e){
    
    var that = this
    wx.request({ //获取金币动态
      url: 'https://www.cerywxr.com/treehole/index.php/Home/sharing/readReport',
      method: "POST", //请求方式,
      header: {
        'content-type': 'application/x-www-form-urlencoded' //POST提交数据方式
      },
      data: {
        msg_id: e.currentTarget.dataset.msgid,
      },
      success(res) {
        that.onShow()
      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    wx.showLoading()
    var that = this
    var user_id = getApp().globalData.userInfo.user_id
    if (user_id == null) {
      //跳转至授权登录界面
      wx.navigateTo({
        url: '../login/login',
      })
    } else {
      wx.request({ //获取金币动态
        url: 'https://www.cerywxr.com/treehole/index.php/Home/sharing/get_message',
        method: "POST", //请求方式,
        header: {
          'content-type': 'application/x-www-form-urlencoded' //POST提交数据方式
        },
        data: {
          my_id: user_id,
        },
        success(res) {
          console.log(res.data.data)
          that.setData({
            msgAll: res.data.data,
          })
          that.setData({
            msgInfo: that.data.msgAll.slice(0, that.data.skipNum),
            start: that.data.skipNum,
          })
          console.log(that.data.msgInfo)
          wx.hideLoading()
        }
      })
    }
  },

   //触底刷新，获取更多
   onReachBottom:function(){
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    var end=that.data.start+that.data.skipNum
    var newData=that.data.msgAll.slice(that.data.start,end)
    that.setData({
      msgInfo:that.data.msgInfo.concat(newData),//拼接数组
      start:end
    })
    setTimeout(() => {
      wx.hideLoading()
    }, 500);//计时器  
  },

})